package com.bdth.weget.net.codec;

import com.bdth.weget.net.base.SessionData;
import com.bdth.weget.net.bean.ByteMessage;
import com.bdth.weget.net.bean.ChannelStatus;
import com.bdth.weget.net.service.ByteMessageService;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/4/27.
 */
public class Decoder4LoggingOnly extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        byte[] message = new byte[in.readableBytes()];
        in.getBytes(0, message);
        //将报文信息写入到日志中去
        //ByteMessageService.write(new ByteMessage("R",message));
        SessionData.BYTEMESSAGE.offer(new ByteMessage("R",message));
        ByteBuf buf = Unpooled.buffer();
        while (in.isReadable()) {
            buf.writeByte(in.readByte());
        }
        out.add(buf);
    }
}